package hkust.csit5110.android.util;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;

public class AndConstants {
  public static final String CHAT_PORT="5000";
  //public static final String BLOB_URL = "http://143.89.208.23:8888/rest/file/url";
  //public static final String VOICE_URL= "http://143.89.208.23:8888/rest/file/";
  public static final String BLOB_URL = "http://echorer.appspot.com/rest/file/url";
  public static final String VOICE_URL= "http://echorer.appspot.com/rest/file/";
  public static final String RECORD_FILE = "record.wav";
  public static final String TEMP_FILE="record_temp.raw";
  public static final String DOWNLOAD_FILE = "match.wav";
  public static final String VOICE_DIR = "/download/";
  //the same constants in app engine
  public static final String GAE_KEY="key";
  public static final String GAE_IP="voiceIp";
  public static final String GAE_VOICE="voice";
  public static final String GAE_ORG_VOICE = "orgVoice";
  public static final String GAE_ORG_EMOTION = "orgEmotion";
  public static final String GAE_ORG_GENDER = "orgGender";
  public static final String GAE_TAR_VOICE = "tarVoice";
  public static final String GAE_TAR_EMOTION = "tarEmotion";
  public static final String GAE_TAR_GENDER = "tarGender";
  public static String localIpAddress;
  
  /**
   * Actually it is not a constants :)
   */
  public static String getLocalIpAddress() {
    if(localIpAddress!=null){
      return localIpAddress;
    }     
    try {
      for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
        NetworkInterface intf = en.nextElement();
        for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
          InetAddress inetAddress = enumIpAddr.nextElement();
          if (!inetAddress.isLoopbackAddress()) {
            localIpAddress = inetAddress.getHostAddress().toString();
          }
        }
      }
    } catch (SocketException ex) {
      ex.printStackTrace();
    }
    return localIpAddress;
  }
}
